package com.ruoyi.comn.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.comn.domain.SrmSupplier;
import com.ruoyi.comn.service.ISrmSupplierService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 供应商管理Controller
 * 
 * @author ruoyi
 * @date 2022-04-19
 */
@RestController
@RequestMapping("/comn/supplier")
public class SrmSupplierController extends BaseController
{
    @Autowired
    private ISrmSupplierService srmSupplierService;

    /**
     * 查询供应商管理列表
     */
    @PreAuthorize(hasPermi = "comn:supplier:list")
    @GetMapping("/list")
    public TableDataInfo list(SrmSupplier srmSupplier)
    {
        startPage();
        List<SrmSupplier> list = srmSupplierService.selectSrmSupplierList(srmSupplier);
        return getDataTable(list);
    }

    /**
     * 导出供应商管理列表
     */
    @PreAuthorize(hasPermi = "comn:supplier:export")
    @Log(title = "供应商管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrmSupplier srmSupplier) throws IOException
    {
        List<SrmSupplier> list = srmSupplierService.selectSrmSupplierList(srmSupplier);
        ExcelUtil<SrmSupplier> util = new ExcelUtil<SrmSupplier>(SrmSupplier.class);
        util.exportExcel(response, list, "供应商管理数据");
    }

    /**
     * 获取供应商管理详细信息
     */
    @PreAuthorize(hasPermi = "comn:supplier:query")
    @GetMapping(value = "/{supplierUuid}")
    public AjaxResult getInfo(@PathVariable("supplierUuid") String supplierUuid)
    {
        return AjaxResult.success(srmSupplierService.selectSrmSupplierBySupplierUuid(supplierUuid));
    }

    /**
     * 新增供应商管理
     */
    @PreAuthorize(hasPermi = "comn:supplier:add")
    @Log(title = "供应商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrmSupplier srmSupplier)
    {
        srmSupplier.setCreateBy(SecurityUtils.getUsername());
        return toAjax(srmSupplierService.insertSrmSupplier(srmSupplier));
    }

    /**
     * 修改供应商管理
     */
    @PreAuthorize(hasPermi = "comn:supplier:edit")
    @Log(title = "供应商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SrmSupplier srmSupplier)
    {
        return toAjax(srmSupplierService.updateSrmSupplier(srmSupplier));
    }

    /**
     * 删除供应商管理
     */
    @PreAuthorize(hasPermi = "comn:supplier:remove")
    @Log(title = "供应商管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{supplierUuids}")
    public AjaxResult remove(@PathVariable String[] supplierUuids)
    {
        return toAjax(srmSupplierService.deleteSrmSupplierBySupplierUuids(supplierUuids));
    }
}
